﻿using FTBS.Models.BLO;
using FTBS.Models.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FTBS.Controllers
{
    public class ChairTypeController : Controller
    {
        ChairTypeBLO _chairTypeBO = new ChairTypeBLO();

        public ActionResult Index()
        {
            if (this.Session["RoleName"] == null || this.Session["UserName"] == null || this.Session["Account"] == null || this.Session["RoleName"].ToString().Trim() != "Staff")
            {
                return Redirect("/Home/Announcement");
            }
            return View(_chairTypeBO.LoadChairTypes());
        }

        #region Create, Edit, Delete

        ////--------------Create--------------------------
        //public ActionResult Create()
        //{
        //    if (this.Session["RoleName"] == null || this.Session["UserName"] == null || this.Session["Account"] == null || this.Session["RoleName"].ToString().Trim() != "Staff")
        //    {
        //        return Redirect("/Home/Announcement");
        //    }
        //    ViewBag.TypeName = null;
        //    return View();
        //}

        //[HttpPost]
        //public ActionResult Create(ChairType chairType)
        //{
        //    if (this.Session["RoleName"] == null || this.Session["UserName"] == null || this.Session["Account"] == null || this.Session["RoleName"].ToString().Trim() != "Staff")
        //    {
        //        return Redirect("/Home/Announcement");
        //    }
        //    if (ModelState.IsValid)
        //    {
        //        if (!_chairTypeBO.CheckExistedChairType(chairType))
        //        {
        //            ViewBag.TypeName = null;
        //            _chairTypeBO.CreateChairType(chairType);
        //            return RedirectToAction("Index");
        //        }
        //        ViewBag.TypeName = chairType.TypeName;
        //        return View(chairType);
        //    }
        //    if (_chairTypeBO.CheckExistedChairType(chairType))
        //    {
        //        ViewBag.TypeName = chairType.TypeName;
        //    }
        //    return View(chairType);
        //}

        ////------------Edit------------------------------
        //public ActionResult Edit(int cTypeId = 0)
        //{
        //    if (this.Session["RoleName"] == null || this.Session["UserName"] == null || this.Session["Account"] == null || this.Session["RoleName"].ToString().Trim() != "Staff")
        //    {
        //        return Redirect("/Home/Announcement");
        //    }
        //    ChairType chairType = _chairTypeBO.SelectChairType(cTypeId);
        //    if (chairType == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    ViewBag.TypeName = null;
        //    return View(chairType);

        //}

        //[HttpPost]
        //public ActionResult Edit(ChairType chairType)
        //{
        //    if (this.Session["RoleName"] == null || this.Session["UserName"] == null || this.Session["Account"] == null || this.Session["RoleName"].ToString().Trim() != "Staff")
        //    {
        //        return Redirect("/Home/Announcement");
        //    }
        //    int id = chairType.ChairTypeId;
        //    int compare = String.Compare(chairType.TypeName, _chairTypeBO.GetChairTypeById(id).TypeName);
        //    if (ModelState.IsValid)
        //    {
        //        if (!_chairTypeBO.CheckExistedChairType(chairType) || (_chairTypeBO.CheckExistedChairType(chairType) && compare == 0))
        //        {
        //            ViewBag.TypeName = null;
        //            _chairTypeBO.EditChairType(chairType);
        //            return RedirectToAction("Index");
        //        }
        //        else if (_chairTypeBO.CheckExistedChairType(chairType) && compare != 0)
        //        {
        //            ViewBag.TypeName = chairType.TypeName;
        //            return View(chairType);
        //        }
        //    }
        //    ViewBag.TypeName = chairType.TypeName;
        //    if (_chairTypeBO.CheckExistedChairType(chairType) && compare == 0)
        //    {
        //        ViewBag.TypeName = null;
        //    }
        //    return View(chairType);
        //}

        ////------------------Delete---------------------
        //[HttpDelete, ActionName("Delete")]
        //public ActionResult Delete(int id = 0)
        //{
        //    if (this.Session["RoleName"] == null || this.Session["UserName"] == null || this.Session["Account"] == null || this.Session["RoleName"].ToString().Trim() != "Staff")
        //    {
        //        return Redirect("/Home/Announcement");
        //    }
        //    ChairType chairType = _chairTypeBO.SelectChairType(id);
        //    if (chairType == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    _chairTypeBO.DeleteChairType(chairType);
        //    return RedirectToAction("Index");
        //}

        #endregion
    }
}
